package com.mashibing.serviceverificationcode.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NacosTestController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @GetMapping("/getPort")
    public String getPort() {
        List<String> services = discoveryClient.getServices();
        for (String service : services) {
            List<ServiceInstance> instances = discoveryClient.getInstances(service);
            for (ServiceInstance instance : instances) {
                System.out.println(instance.getServiceId());
                System.out.println(instance.getHost());
                System.out.println(instance.getPort());
            }
        }
        return "success";
    }
}
